
//
//  TZBuyViewController.m
//  wangYiCaiPiao
//
//  Created by mac on 16/1/6.
//  Copyright © 2016年 tz. All rights reserved.
//

#import "TZBuyViewController.h"
#import "TZBuyButton.h"

@interface TZBuyViewController ()
@property (nonatomic, strong) UIView *backView;
@property (nonatomic, strong) UIView *didButton; //点击全部彩种时弹出的页面
@end

@implementation TZBuyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    //添加视图背景图层
    self.backView = [[UIView alloc] init];
    self.backView.frame = CGRectMake(0, 0, 100, 25);
    self.navigationItem.titleView = self.backView;
    [self setupUI];
}

//button监听事件
- (void)buttonDidClick:(UIButton *)sender {
    [UIView animateWithDuration:0.25 animations:^{
        CGRect rect = self.didButton.frame;
        //三目运算
        rect.size.height = rect.size.height ? 0 : 300;
        //小三角旋转
        sender.imageView.transform = CGAffineTransformRotate(sender.imageView.transform, M_PI);
        self.didButton.frame = rect;
    }];
}

//更新UI
- (void)setupUI {
    [self addButtonInController];
}

//点击的button
- (void)addButtonInController {
    TZBuyButton *button = [[TZBuyButton alloc] init];
    [self.backView addSubview:button];
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.backView);
    }];
    [button setImage:[UIImage imageNamed:@"YellowDownArrow"] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:@"YellowDownArrow"] forState:UIControlStateHighlighted];
    [button setTitle:@"全部彩种" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    //点击事件
    [button addTarget:self action:@selector(buttonDidClick:) forControlEvents:UIControlEventTouchUpInside];
}

//懒加载
- (UIView *)didButton {
    if (_didButton == nil) {
        UIView *view = [[UIView alloc] init];
        [self.view addSubview:view];
        view.frame = CGRectMake(0, 0, KSCREEN_WIDTH, 0);
        view.backgroundColor = [UIColor yellowColor];
        _didButton = view;
    }
    return _didButton;
}
@end
